home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2009 February / PCWFEB09.iso / Software / Resources / Chat & Communication / Digsby build 37 / digsby_setup.exe / lib / ntpath.pyo (.txt) < prev    next >
Encoding:
Python Compiled Bytecode  |  2008-10-13  |  8.4 KB  |  415 lines

  1. # Source Generated with Decompyle++
  2. # File: in.pyo (Python 2.5)
  3.  
  4. import os
  5. import stat
  6. import sys
  7. __all__ = [
  8.     'normcase',
  9.     'isabs',
  10.     'join',
  11.     'splitdrive',
  12.     'split',
  13.     'splitext',
  14.     'basename',
  15.     'dirname',
  16.     'commonprefix',
  17.     'getsize',
  18.     'getmtime',
  19.     'getatime',
  20.     'getctime',
  21.     'islink',
  22.     'exists',
  23.     'lexists',
  24.     'isdir',
  25.     'isfile',
  26.     'ismount',
  27.     'walk',
  28.     'expanduser',
  29.     'expandvars',
  30.     'normpath',
  31.     'abspath',
  32.     'splitunc',
  33.     'curdir',
  34.     'pardir',
  35.     'sep',
  36.     'pathsep',
  37.     'defpath',
  38.     'altsep',
  39.     'extsep',
  40.     'devnull',
  41.     'realpath',
  42.     'supports_unicode_filenames']
  43. curdir = '.'
  44. pardir = '..'
  45. extsep = '.'
  46. sep = '\\'
  47. pathsep = ';'
  48. altsep = '/'
  49. defpath = '.;C:\\bin'
  50. if 'ce' in sys.builtin_module_names:
  51.     defpath = '\\Windows'
  52. elif 'os2' in sys.builtin_module_names:
  53.     altsep = '/'
  54.  
  55. devnull = 'nul'
  56.  
  57. def normcase(s):
  58.     return s.replace('/', '\\').lower()
  59.  
  60.  
  61. def isabs(s):
  62.     s = splitdrive(s)[1]
  63.     if s != '':
  64.         pass
  65.     return s[:1] in '/\\'
  66.  
  67.  
  68. def join(a, *p):
  69.     path = a
  70.     for b in p:
  71.         b_wins = 0
  72.         if path == '':
  73.             b_wins = 1
  74.         elif isabs(b):
  75.             if path[1:2] != ':' or b[1:2] == ':':
  76.                 b_wins = 1
  77.             elif (len(path) > 3 or len(path) == 3) and path[-1] not in '/\\':
  78.                 b_wins = 1
  79.             
  80.         
  81.         if b_wins:
  82.             path = b
  83.             continue
  84.         if path[-1] in '/\\':
  85.             if b and b[0] in '/\\':
  86.                 path += b[1:]
  87.             else:
  88.                 path += b
  89.         b[0] in '/\\'
  90.         if path[-1] == ':':
  91.             path += b
  92.             continue
  93.         if b:
  94.             if b[0] in '/\\':
  95.                 path += b
  96.             else:
  97.                 path += '\\' + b
  98.         b[0] in '/\\'
  99.         path += '\\'
  100.     
  101.     return path
  102.  
  103.  
  104. def splitdrive(p):
  105.     if p[1:2] == ':':
  106.         return (p[0:2], p[2:])
  107.     
  108.     return ('', p)
  109.  
  110.  
  111. def splitunc(p):
  112.     if p[1:2] == ':':
  113.         return ('', p)
  114.     
  115.     firstTwo = p[0:2]
  116.     if firstTwo == '//' or firstTwo == '\\\\':
  117.         normp = normcase(p)
  118.         index = normp.find('\\', 2)
  119.         if index == -1:
  120.             return ('', p)
  121.         
  122.         index = normp.find('\\', index + 1)
  123.         if index == -1:
  124.             index = len(p)
  125.         
  126.         return (p[:index], p[index:])
  127.     
  128.     return ('', p)
  129.  
  130.  
  131. def split(p):
  132.     (d, p) = splitdrive(p)
  133.     i = len(p)
  134.     while i and p[i - 1] not in '/\\':
  135.         i = i - 1
  136.     head = p[:i]
  137.     tail = p[i:]
  138.     head2 = head
  139.     while head2 and head2[-1] in '/\\':
  140.         head2 = head2[:-1]
  141.     if not head2:
  142.         pass
  143.     head = head
  144.     return (d + head, tail)
  145.  
  146.  
  147. def splitext(p):
  148.     i = p.rfind('.')
  149.     if i <= max(p.rfind('/'), p.rfind('\\')):
  150.         return (p, '')
  151.     else:
  152.         return (p[:i], p[i:])
  153.  
  154.  
  155. def basename(p):
  156.     return split(p)[1]
  157.  
  158.  
  159. def dirname(p):
  160.     return split(p)[0]
  161.  
  162.  
  163. def commonprefix(m):
  164.     if not m:
  165.         return ''
  166.     
  167.     s1 = min(m)
  168.     s2 = max(m)
  169.     n = min(len(s1), len(s2))
  170.     for i in xrange(n):
  171.         if s1[i] != s2[i]:
  172.             return s1[:i]
  173.             continue
  174.     
  175.     return s1[:n]
  176.  
  177.  
  178. def getsize(filename):
  179.     return os.stat(filename).st_size
  180.  
  181.  
  182. def getmtime(filename):
  183.     return os.stat(filename).st_mtime
  184.  
  185.  
  186. def getatime(filename):
  187.     return os.stat(filename).st_atime
  188.  
  189.  
  190. def getctime(filename):
  191.     return os.stat(filename).st_ctime
  192.  
  193.  
  194. def islink(path):
  195.     return False
  196.  
  197.  
  198. def exists(path):
  199.     
  200.     try:
  201.         st = os.stat(path)
  202.     except os.error:
  203.         return False
  204.  
  205.     return True
  206.  
  207. lexists = exists
  208.  
  209. def isdir(path):
  210.     
  211.     try:
  212.         st = os.stat(path)
  213.     except os.error:
  214.         return False
  215.  
  216.     return stat.S_ISDIR(st.st_mode)
  217.  
  218.  
  219. def isfile(path):
  220.     
  221.     try:
  222.         st = os.stat(path)
  223.     except os.error:
  224.         return False
  225.  
  226.     return stat.S_ISREG(st.st_mode)
  227.  
  228.  
  229. def ismount(path):
  230.     (unc, rest) = splitunc(path)
  231.     if unc:
  232.         return rest in ('', '/', '\\')
  233.     
  234.     p = splitdrive(path)[1]
  235.     if len(p) == 1:
  236.         pass
  237.     return p[0] in '/\\'
  238.  
  239.  
  240. def walk(top, func, arg):
  241.     
  242.     try:
  243.         names = os.listdir(top)
  244.     except os.error:
  245.         return None
  246.  
  247.     func(arg, top, names)
  248.     exceptions = ('.', '..')
  249.     for name in names:
  250.         if name not in exceptions:
  251.             name = join(top, name)
  252.             if isdir(name):
  253.                 walk(name, func, arg)
  254.             
  255.         isdir(name)
  256.     
  257.  
  258.  
  259. def expanduser(path):
  260.     if path[:1] != '~':
  261.         return path
  262.     
  263.     i = 1
  264.     n = len(path)
  265.     while i < n and path[i] not in '/\\':
  266.         i = i + 1
  267.     if i == 1:
  268.         if 'HOME' in os.environ:
  269.             userhome = os.environ['HOME']
  270.         elif 'HOMEPATH' not in os.environ:
  271.             return path
  272.         else:
  273.             
  274.             try:
  275.                 drive = os.environ['HOMEDRIVE']
  276.             except KeyError:
  277.                 drive = ''
  278.  
  279.             userhome = join(drive, os.environ['HOMEPATH'])
  280.     else:
  281.         return path
  282.     return userhome + path[i:]
  283.  
  284.  
  285. def expandvars(path):
  286.     if '$' not in path:
  287.         return path
  288.     
  289.     import string
  290.     varchars = string.ascii_letters + string.digits + '_-'
  291.     res = ''
  292.     index = 0
  293.     pathlen = len(path)
  294.     while index < pathlen:
  295.         c = path[index]
  296.         if c == "'":
  297.             path = path[index + 1:]
  298.             pathlen = len(path)
  299.             
  300.             try:
  301.                 index = path.index("'")
  302.                 res = res + "'" + path[:index + 1]
  303.             except ValueError:
  304.                 res = res + path
  305.                 index = pathlen - 1
  306.             except:
  307.                 None<EXCEPTION MATCH>ValueError
  308.             
  309.  
  310.         None<EXCEPTION MATCH>ValueError
  311.         if c == '$':
  312.             if path[index + 1:index + 2] == '$':
  313.                 res = res + c
  314.                 index = index + 1
  315.             elif path[index + 1:index + 2] == '{':
  316.                 path = path[index + 2:]
  317.                 pathlen = len(path)
  318.                 
  319.                 try:
  320.                     index = path.index('}')
  321.                     var = path[:index]
  322.                     if var in os.environ:
  323.                         res = res + os.environ[var]
  324.                 except ValueError:
  325.                     res = res + path
  326.                     index = pathlen - 1
  327.                 except:
  328.                     None<EXCEPTION MATCH>ValueError
  329.                 
  330.  
  331.             None<EXCEPTION MATCH>ValueError
  332.             var = ''
  333.             index = index + 1
  334.             c = path[index:index + 1]
  335.             while c != '' and c in varchars:
  336.                 var = var + c
  337.                 index = index + 1
  338.                 c = path[index:index + 1]
  339.             if var in os.environ:
  340.                 res = res + os.environ[var]
  341.             
  342.             if c != '':
  343.                 res = res + c
  344.             
  345.         else:
  346.             res = res + c
  347.         index = index + 1
  348.     return res
  349.  
  350.  
  351. def normpath(path):
  352.     path = path.replace('/', '\\')
  353.     (prefix, path) = splitdrive(path)
  354.     if prefix == '':
  355.         while path[:1] == '\\':
  356.             prefix = prefix + '\\'
  357.             path = path[1:]
  358.     elif path.startswith('\\'):
  359.         prefix = prefix + '\\'
  360.         path = path.lstrip('\\')
  361.     
  362.     comps = path.split('\\')
  363.     i = 0
  364.     while i < len(comps):
  365.         if comps[i] in ('.', ''):
  366.             del comps[i]
  367.             continue
  368.         if comps[i] == '..':
  369.             if i > 0 and comps[i - 1] != '..':
  370.                 del comps[i - 1:i + 1]
  371.                 i -= 1
  372.             elif i == 0 and prefix.endswith('\\'):
  373.                 del comps[i]
  374.             else:
  375.                 i += 1
  376.         prefix.endswith('\\')
  377.         i += 1
  378.     if not prefix and not comps:
  379.         comps.append('.')
  380.     
  381.     return prefix + '\\'.join(comps)
  382.  
  383.  
  384. try:
  385.     from nt import _getfullpathname
  386. except ImportError:
  387.     
  388.     def abspath(path):
  389.         if not isabs(path):
  390.             path = join(os.getcwd(), path)
  391.         
  392.         return normpath(path)
  393.  
  394.  
  395.  
  396. def abspath(path):
  397.     if path:
  398.         
  399.         try:
  400.             path = _getfullpathname(path)
  401.         except WindowsError:
  402.             pass
  403.         except:
  404.             None<EXCEPTION MATCH>WindowsError
  405.         
  406.  
  407.     None<EXCEPTION MATCH>WindowsError
  408.     path = os.getcwd()
  409.     return normpath(path)
  410.  
  411. realpath = abspath
  412. if hasattr(sys, 'getwindowsversion'):
  413.     pass
  414. supports_unicode_filenames = sys.getwindowsversion()[3] >= 2
  415.